import { request, useUserStore, clearEmpty } from "jmash-core";
import type { AxiosPromise } from "axios";
import type {
  HiProcInstModel,
  HiProcInstKey,
  HiProcInstReq,
  HiProcInstPage,
} from "./types";
import type { FinishInstApi } from "./types";
import type {
  FlowProcInstKey,
  FlowCompleteTaskRequest,
} from "@/api/flow/task/types";

class FinishInstApiImpl implements FinishInstApi {
  getKey(model: HiProcInstModel): HiProcInstKey {
    return {
      procInstId: model.id,
    } as HiProcInstKey;
  }

  // 获取我的办结事项
  findPage(req: HiProcInstReq): AxiosPromise<HiProcInstPage> {
    const tenant = useUserStore().user.tenant;
    clearEmpty(req);
    return request({
      url: "/v1/flow/task/myfinish/page/" + tenant,
      method: "get",
      params: req,
    });
  }

  // 获取历史流程实例变量
  findHiProcinstId(
    req: FlowProcInstKey,
  ): AxiosPromise<FlowCompleteTaskRequest> {
    const tenant = useUserStore().user.tenant;
    clearEmpty(req);
    clearEmpty(req);
    return request({
      url: "/v1/flow/hi_procinst/vars/" + tenant + "/" + req.procInstId,
      method: "get",
    });
  }
}
const finishInstApi = new FinishInstApiImpl();

export { finishInstApi };
